<?php $this->import('Header') ?>
<?php $this->addJs('js/swfupload.js') ?>
<?php $this->addJs('js/handlers.js') ?>
<div style="height: 30px;"></div>
<div class="well">
	<div class="tab-content">
		<div class="tab-pane active in">
			<h3><?php echo !empty($data['WorkId']) ? '修改作品' : '添加作品' ?></h3>
			<div id="message-box"></div>
			<form method="post" onsubmit="return doSubmit(this)">
				<input type="hidden" name="workId" value="<?php echo empty($data['WorkId']) ? '' : $data['WorkId'] ?>" />
				<div style="display: none" id="js-id-box"></div>
				<label>作品名称</label>
				<input type="text" name="name" value="<?php echo $data['Name'] ?>" class="input-xlarge"> <input type="text" name="tip" class="input-mini" value="<?php echo $data['Tip'] ?>"  />
				<label>价格</label>
				<input type="text" name="price" value="<?php echo $data['Price'] ?>" class="input-xlarge">
				<label>作品描述</label>
				<textarea name="desc" id="js-content" class="input-xxlarge" style="height:150px;" type="text/plain"><?php echo $data['WorkDesc'] ?></textarea>
				<label>作品简介</label>
				<textarea name="introduction" id="js-content" class="input-xxlarge" style="height:150px;" type="text/plain"><?php echo $data['Introduction'] ?></textarea>
				<div style="width: 610px; height: auto; border: 1px solid #e1e1e1; font-size: 12px; padding: 10px;">
					<span id="spanButtonPlaceholder"></span>
					<div id="divFileProgressContainer"></div>
					<div id="thumbnails">
						<ul id="pic_list" style="margin: 5px;"></ul>
						<div style="clear: both;"></div>
					</div>
				</div>
				<label>状态</label>
				<div class="select">
					<select name="status">
						<option value="1">显示</option>
						<option value="0" <?php echo $data['Status'] == 0 ? 'selected' : '' ?> >隐藏</option>
					</select>
				</div>
				<label>是否热门</label>
				<div class="select">
					<select name="isHot">
						<option value="1">是</option>
						<option value="0" <?php echo $data['IsHot'] == 0 ? 'selected' : '' ?>>否</option>
					</select>
				</div>
				<label>类型</label>
				<div class="select">
					<select name="type">
						<option value="1">首页作品</option>
						<option value="2" <?php echo $data['Type'] == 2 ? 'selected' : '' ?>>攻略汇总</option>
						<option value="3" <?php echo $data['Type'] == 3 ? 'selected' : '' ?>>最新动态</option>
					</select>
				</div>
				<input type="hidden" name="s" id="" value="<?php echo $data['Pic'] ?>"/>
				<label>选择标签</label>
				<div id="js-selected-tag-box" style="min-height:20px;"></div>
				<div style="border: 1px solid #ccc; padding: 10px; margin-top: 10px;">
					<div id="js-tag-box" style="margin-top: 5px;">
						<span class="box"></span>
					</div>
				</div>
				<div class="btn-toolbar">
					<button class="btn btn-primary"><i class="icon-save"></i> <?php echo empty($data['WorkId']) ? '添加' : '修改' ?></button>
				</div>
			</form>
		</div>
	</div>
</div>
<?php $this->import('Footer') ?>
<?php
	$this->addJs(array('umeditor/umeditor.config.js','umeditor/umeditor.min.js',));
	$this->addCss('umeditor/themes/default/css/umeditor.css');
?>
<script>
	$('#js-tag-box').tag({
		selectedBox: $('#js-selected-tag-box'),
		addFunc: function(tagId, tagName) {
			var idBox = $('#js-id-box');
			idBox.append('<input name="tagId[]" value="' + tagId + '" />');
		},
		removeFunc: function(tagId, tagName) {
			var idBox = $('#js-id-box');
			idBox.find('input[value="' + tagId + '"]').remove();
		},
		defaultTagIds: <?php echo json_encode($tags) ?>
	});
	var swfu;
	window.onload = function () {
		swfu = new SWFUpload({
			upload_url: "/Upload/SwfImage",
			post_params: {"PHPSESSID": "mbre9e5uglqfh97qekbilm51e5"},
			file_size_limit : "2 MB",
			file_types : "*.jpg;*.png;*.gif;*.bmp",
			file_types_description : "JPG Images",
			file_upload_limit : "20",
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,
			button_image_url : "/Resource/images/upload.png",
			button_placeholder_id : "spanButtonPlaceholder",
			button_width: 113,
			button_height: 33,
			button_text : '',
			button_text_style : '.spanButtonPlaceholder { font-family: Helvetica, Arial, sans-serif; font-size: 14pt;} ',
			button_text_top_padding: 0,
			button_text_left_padding: 0,
			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			button_cursor: SWFUpload.CURSOR.HAND,
			flash_url : "/Resource/swf/swfupload.swf",
			custom_settings : {
				upload_target : "divFileProgressContainer"
			},
			debug: false
		});
		$(function() {
			var str = $('input[name="s"]').val();
			var arr = str ? str.split('|') : [];
			for (var i in arr) {
				addImage(arr[i]);
			}
			var cover = '<?php echo $data['Cover'] ?>';
			$('input[name="cover"]').each(function() {
				var c = $(this).val();
				if (c == cover) {
					$(this).attr('checked', true);
				}
			});
		});
	};

	function doSubmit(obj) {
		var l = $('input[name="tagId[]"]').length;
		if (!l) {
			alert('至少选择一个标签');
			return false;
		}
		return true;
	}
</script>